package com.ricchieri.manage.bean;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.ricchieri.common.BusinessSettings;
import com.ricchieri.filter.CharterFilter;
import com.ricchieri.model.Charter;
import com.ricchieri.model.CharterExpense;
import com.ricchieri.util.FacesUtil;

@ManagedBean(name = "viewCharterExpenseMB")
@ViewScoped
public class ViewCharterExpenseManageBean extends GenericManageBean {

	private static final long serialVersionUID = -4431457088573798836L;
	
	private Charter charter;
	private CharterExpense charterExpense;
	private CharterFilter charterFilter;

	@PostConstruct
	public void init() {
		charterExpense = (CharterExpense) FacesUtil.getParametersFlash(BusinessSettings.KEY_CHARTER_EXPENSE);
		charter = (Charter) FacesUtil.getParametersFlash(BusinessSettings.KEY_CHARTER);
		charterFilter = (CharterFilter) FacesUtil.getParametersFlash(BusinessSettings.KEY_FILTER);
		
		if(charter == null || charterExpense == null) {
			FacesUtil.redirectToNavigationCase(BusinessSettings.SEARCH_CHARTER_EXPENSE);
		}
	}
	
	public Charter getCharter() {
		return charter;
	}

	public void setCharter(Charter charter) {
		this.charter = charter;
	}

	public CharterExpense getCharterExpense() {
		return charterExpense;
	}

	public void setCharterExpense(CharterExpense charterExpense) {
		this.charterExpense = charterExpense;
	}
	
	public String addCharterExpense() {
		FacesUtil.addParametersFlash(BusinessSettings.KEY_CHARTER, charter);
		
		return BusinessSettings.ADD;
	}
	
	public String doBackToSearchCharter() {		
		FacesUtil.addParametersFlash(BusinessSettings.KEY_FILTER, charterFilter);

		return BusinessSettings.SEARCH_CHARTER;
	}	
	
	public String doBackToViewSearchCharter() {		
		FacesUtil.addParametersFlash(BusinessSettings.KEY_FILTER, charterFilter);
		FacesUtil.addParametersFlash(BusinessSettings.KEY_CHARTER, charter);

		return BusinessSettings.VIEW_DETAILS;
	}	
}
